﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A96基本数据类型转换
{
    class Program
    {
        //隐式转换 
        static void Main1(string[] args)
        {
            int a = 521412341;
            float f = a;
            Console.WriteLine(f);

            byte b = 123;
            int a1 = b;
        }
        //强制转换
        static void Main2(string[] args)
        {
            float f = 1.23f;
            int a =(int) f;

            int a1 = 257;
            byte b = (byte) a1;
            Console.WriteLine(b);
        }

        //Convert转换 
        static void Main3(string[] args)
        {
            float f = 1.23f;
            int a = Convert.ToInt32(f);

            int a1 = 4;
            string s= Convert.ToString(a1,2);//转换成二进制字符串
            Console.WriteLine(s.PadLeft(32,'0'));

            int i = 256;
            byte b = (byte)i;//0

           // int i1 = 256;
           // byte b1 = Convert.ToByte(i1);//运行时报错

            string s1 = "123";
            int a2 = Convert.ToInt32( s1);
            Console.WriteLine(a2+1);
        }

        //Parse 字符串转数值类型
        static void Main4(string[] args)
        {
            string s1 = "123";
            int a2 =int.Parse(s1);
            Console.WriteLine(a2 + 1);

            string s2 = "1.23";
            float a3 = float.Parse(s2);

            Console.WriteLine(a2+a3);

            string s3 = a3.ToString(); //"1.23"
        }

        //练习 做一个简单的计算器
        //用户先后输入2个数字  输出两数之和
        static void Main(string[] args)
        {
            Console.WriteLine("请输入第一个数字");
            string s = Console.ReadLine();
            int a = int.Parse(s);

            Console.WriteLine("请输入第二个数字");
            int a1 = int.Parse(Console.ReadLine());

            Console.WriteLine(a+a1);
        }

    }
}
